/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.struts.service.beans;


/**
 * This class corresponds to the "element" element of the menus_conf.xml.
 * It corresponds to an element of a profile specific menu.
 *
 */
public class JBMenuElement
{
    /** Menu element name. */
    private String name;

    /** If "true", use icon, else use label. */
    private String showicon;

    /** Computed menu element. */
    private JBFeature feature;

    /**
     * Returns the menu element name.
     * @return name
     */
    public String getName()
    {
        return name;
    }

    /**
     * Returns the "show icon" flag.
     * @return If "true", should show icon, else should show label.
     */
    public String getShowicon()
    {
        return showicon;
    }

    /**
     * Sets the menu element name.
     * @param aname The name to set
     */
    public void setName(String aname)
    {
        this.name = aname;
    }

    /**
     * Sets the "show icon" flag..
     * @param ashowicon If "true", should show icon, else should show label.
     */
    public void setShowicon(String ashowicon)
    {
        this.showicon = ashowicon;
    }

    /**
     * Not used.
     * @param atype Not used
     */
    public void setType(String atype)
    {
        // nothing to do
        return;
    }

    /**
     * Displays menu element definition.
     *
     * @return String formatted menu element definition
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        java.util.Iterator it = null;

        buf.append("name = ");
        buf.append(name);
        buf.append(System.getProperty("line.separator"));
        buf.append("showicon = ");
        buf.append(showicon);
        buf.append(System.getProperty("line.separator"));
        buf.append("feature = ");
        buf.append(feature);
        buf.append(System.getProperty("line.separator"));

        return buf.toString();
    }

    // end of toString method

    /**
     * Returns the menu element.
     * @return menu element
     */
    public JBFeature getFeature()
    {
        return feature;
    }

    /**
     * Sets the menu element.
     * @param afeature The feature to set
     */
    public void setFeature(JBFeature afeature)
    {
        this.feature = afeature;
    }

    /**
     * Checks whether menu element display should use icon or label.
     *
     * @return true : use icon, false : use label
     */
    public boolean useIcon()
    {
        if (showicon == null)
        {
            return false;
        }
        else
        {
            return (showicon.compareToIgnoreCase("true") == 0);
        }
    }
}
